package com.pyrsana.faith.membership

import com.pyrsana.contact.Address
import com.pyrsana.contact.EmailAddress
import com.pyrsana.contact.PhoneNumber

class Profile {

    static hasMany = [addresses:Address, emailAddresses:EmailAddress, phoneNumbers:PhoneNumber]
    
    String first
    String middle
    String last
    String gender
    Date birthday
    Date dateCreated
    Date lastUpdated

    static constraints = {
        first (size: 2..15, blank: false)
        last (size: 2..15, blank: false)
        middle (size: 0..15, nullable: true)
        gender (size: 1..1)
        birthday (max: new Date())
    }
    
    static mapping = { 
        autoTimestamp true
        addresses cascade: 'all-delete-orphan'
        emailAddresses cascade: 'all-delete-orphan'
        phoneNumbers cascade: 'all-delete-orphan'
    }
    
    def String toString() {
        return getFullName()
    }
	
	def String getFullName() {
		String fullName = first
		if (middle) {
			fullName += ' ' + middle
		}
		fullName += ' ' + last
		return fullName
	}
}
